<script>
export default {
  name: "MySilder",
  props: {},
  computed: {
    // message() {
    //   return this.$store.getters.message;
    // },
  },
  data() {
    return {
      message: "",
    };
  },
  beforeMount() {},
  mounted() {
    console.log(this.$store);
  },
  created() {
    this.$bus.$on('message-from-a', (msg) => {
      console.log('message-from-a', msg);
      this.message = msg;
    });
  },
  beforeDestroy() {
    // 防止内存泄漏，组件销毁时移除事件监听
      this.$bus.$off('message-from-a');
  },
  methods: {
    sendMessage() {
        this.$bus.$emit('message-from-a', '来自MyNav的消息');
        this.message = '';
    }
  },
};
</script>
<template>
  <div>
    <h3>我是侧边栏</h3>
    <button @click="sendMessage">发送消息到MyNav</button>
   <p>来自MyNav的消息：</p> {{ message }}
  </div>
</template>
